package com.wy.tingshu.util;




import com.mysql.cj.jdbc.MysqlDataSource;
import lombok.SneakyThrows;

import javax.sql.DataSource;
import java.sql.Connection;

public class DBUtil {
    private static final DataSource dataSource;

    static {
        MysqlDataSource mysqlDataSource = new MysqlDataSource();
        mysqlDataSource.setUrl("jdbc:mysql:///tingshu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai");
        mysqlDataSource.setUser("root");
        mysqlDataSource.setPassword("5695604033gwy");
        dataSource = mysqlDataSource;
    }

    @SneakyThrows//加上这个所有的受查异常就自己转为非受查异常了，不用自己写catch抛出了【添加pom.xml中的lombok依赖】
    public static Connection connection() {
        return dataSource.getConnection();
    }
}
